package com.jimmyhsu.nestedscrolldemo;

import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jimmyhsu.nestedscrolldemo.view.CircleDrawable;
import com.jimmyhsu.nestedscrolldemo.view.TwoLevelMenuLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jimmyhsu on 2017/1/16.
 */

public class MainActivity extends AppCompatActivity {

    @BindView(R.id.id_two_level_menu)
    TwoLevelMenuLayout mTwoLevelLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two_level_menu);
        ButterKnife.bind(this);
        List<String> datas = new ArrayList<>();
        for (int i = 0; i < 12; i++) {
            datas.add("Title " + i);
        }
        mTwoLevelLayout.setAdapter(new TwoLevelMenuLayout.TwoLevelMenuAdapter() {
            LayoutInflater mInfalter = LayoutInflater.from(getApplicationContext());
            @Override
            public View getTitleView(int position) {
                View titleView = mInfalter.inflate(R.layout.tlm_title, mTwoLevelLayout, false);
                ((TextView)(titleView)).setText("分组" + (position + 1));
                return titleView;
            }

            @Override
            public View getSecondView(int titlePos, int itemPos) {
                View childView = mInfalter.inflate(R.layout.tlm_item, mTwoLevelLayout, false);
                ImageView mIvHead = (ImageView) childView.findViewById(R.id.id_tl_item_head);
                TextView mTvName = (TextView) childView.findViewById(R.id.id_tl_item_name);
                TextView mTvSignature = (TextView) childView.findViewById(R.id.id_tl_item_signature);
                mIvHead.setImageDrawable(new CircleDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.userface)));
                mTvName.setText("第" + (titlePos + 1) + "组第" + (itemPos + 1) + "个联系人");
                mTvSignature.setText("are you ok");
                return childView;
            }

            @Override
            public int getTitleCount() {
                return 10;
            }

            @Override
            public int getSecondCount(int titlePos) {
                return 8;
            }
        });
        mTwoLevelLayout.setOnItemClickListner(new TwoLevelMenuLayout.OnItemClickListner() {
            @Override
            public void onTitleClick(View v, int titlePos) {

            }

            @Override
            public void onSecondItemClick(View v, int titlePos, int itemPos) {
                Snackbar.make(mTwoLevelLayout, "点击了" + titlePos + "-" + itemPos, Snackbar.LENGTH_SHORT).show();
            }
        });
    }
}
